<template>
  <div class="box111">
    <el-form :model="form" label-width="auto" style="max-width: 600px">
      <el-form-item label="标题">
        <el-input v-model="form.content" />
      </el-form-item>
      <el-form-item label="内容">
        <el-input v-model="form.title" />
      </el-form-item>
      <el-form-item label="是否公开：" class="you">
        <el-switch v-model="form.status" />
      </el-form-item>
      <el-form-item class="you">
        <el-button type="primary" @click="onSubmit()">发布</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts" setup>
import http from '@/http/http'
import { reactive } from 'vue'

// do not use same name with ref
const form = reactive({
  content: '',
  title: '',
  status: false
})

function onSubmit() {
  http({
    url: '/posts',
    method: 'post',
    data: {
      title: form.title,
      content: form.content,
      status: form.status
    }
  }).then(() => {
    console.log('文章发布成功')
    form.title = ''
    form.content = ''
    form.status = false
  })
}
</script>
<style scoped>
.box111 {
  width: 80%;
  display: flex;
  justify-content: flex-end;
  margin-top: 50px;
}
.you {
  margin-left: 42px;
}
</style>
